package com.jml.jdk8.方法引用;


import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;

/**
 * @author:jml
 * @date: 2019/12/3 0003 22:12
 * @description：
 */
public class Jdk自带的排序 {

    public static void main(String[] args) {
        List<String> citice = Arrays.asList("qingdao", "chongqing", "tianjin", "beijing");
        Collections.sort(citice,(c1,c2)-> c1.compareToIgnoreCase(c2));
        citice.forEach(a-> System.out.println(a));

        //compareToIgnoreCase是字符串对象调用的，接收一个参数，返回一个整型
        Comparator<String> compareToIgnoreCase = String::compareToIgnoreCase;
        Collections.sort(citice,String::compareToIgnoreCase);
        citice.forEach(a-> System.out.println(a));

        Function<Student, String> function = Student::getName;
        BiConsumer<Student, String> biConsumer = Student::setName;
        Student s1 = new Student();
        //因为biConsumer接收两个参数没有返回，相当于s1去调用setName方法，nnnn是作为参数
        setName(s1,"nnnn", Student::setName);
        //因为function接收一个参数返回一个参数，相当于s1去调用getName方法
        getName(s1, Student::getName);
        System.out.println(s1);
    }

    public static void setName(Student s1,String str,BiConsumer<Student, String> biConsumer){
        biConsumer.accept(s1,str);
    }
    public static void getName(Student s1,Function<Student, String> function){
        String apply = function.apply(s1);
        System.out.println(apply);
    }
}
